package com.dingreading.cloud.ssxcx.service.impl;

import com.dingreading.cloud.ssxcx.entity.XcxHomeworkFiles;
import com.dingreading.cloud.ssxcx.entity.XcxStudentHomework;
import com.dingreading.cloud.ssxcx.entity.table.XcxHomeworkFilesTableDef;
import com.dingreading.cloud.ssxcx.mapper.XcxHomeworkFilesMapper;
import com.dingreading.cloud.ssxcx.service.XcxHomeworkFilesService;
import com.mybatisflex.core.query.QueryCondition;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 小程序课后作业文件表 服务层实现。
 *
 * @author EDY
 * @since 2025-08-23
 */
@Service
public class XcxHomeworkFilesServiceImpl extends BaseServiceImpl<XcxHomeworkFilesMapper, XcxHomeworkFiles, XcxHomeworkFilesTableDef> implements XcxHomeworkFilesService {

    @Override
    protected XcxHomeworkFilesTableDef getTable() {
        return XcxHomeworkFilesTableDef.xcxHomeworkFiles;
    }

    @Override
    public Boolean deleteByHomeworkUid(XcxStudentHomework homework) {
        QueryCondition condition = QueryCondition.createEmpty()
                .and(table.homeworkUid.eq(homework.getUid()))
                .and(table.enabled.eq(1));
        long l = getMapper().selectCountByCondition(condition);
        if (l == 0) return true;

        return getMapper().deleteByCondition(condition) > 0;
    }

    @Override
    public List<XcxHomeworkFiles> getByHomeworkUid(String homeworkUid) {
        QueryCondition condition = QueryCondition.createEmpty()
                .and(table.homeworkUid.eq(homeworkUid))
                .and(table.enabled.eq(1));
        return getMapper().selectListByCondition(condition);
    }
}
